﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace DevDemo
{
    public partial class DevVScrollBarDemo : Form
    {
        public DevVScrollBarDemo()
        {
            InitializeComponent();
        }

        private void DevVScrollBarDemo_Load(object sender, EventArgs e)
        {
           
            int height = 0;

            for (int i = 0; i < 10; i++)
            {
                GroupControl gp = new GroupControl();

                gp.Text = "Group" + i.ToString();

                gp.Location = new Point(10, 120 * i);

                gp.Height = 100;

                height += 100;

                gp.Dock = DockStyle.Top;

                this.panel1.Controls.Add(gp);

                this.panel1.Height = height + 80;
            }

            //MessageBox.Show(this.Height.ToString() + "---" + this.panelControl1.Height.ToString(), "height");

            // 设置滚动条滑块大小
            this.vScrollBar1.LargeChange = (this.panel1.Height - this.Height) / 4;

            vScrollBar1.Maximum = this.panel1.Height - this.Height;
        }

        private void vScrollBar1_Scroll_1(object sender, ScrollEventArgs e)
        {
            Point p = panel1.Location;

            p.Y = 0 - (int)(e.NewValue);

            panel1.Top = p.Y;

            Text = e.OldValue.ToString() + " | " + e.NewValue.ToString() + " | " + vScrollBar1.Value.ToString();
        }

        private void panelControl1_MouseClick(object sender, MouseEventArgs e)
        {
            vScrollBar1.Focus();//
        }
    }
}
